<?php
/**
 * PropertyObject class definition
 *  
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MVP-PHP
 */
 
 /**
  * This base class provides functionality for read only and write only
  * properties. Properties that are read and write should simply be declared
  * public.
  * @package MVP-PHP
  * @subpackage Base 
  */      
class PropertyObject
{
	/**
 	 * Magic getter
	 * @param string $name
	 * @return mixed
	 */   	
	public function __get($name)
	{
		if (in_array($name, $this->writeOnly)) {
			throw new WriteOnlyPropertyException(get_class($this), $name);
		} elseif (in_array($name, $this->readOnly)) {
			return $this->$name;
		} else {
			throw new InaccessiblePropertyException(get_class($this), $name);
		} 
	}
	
	/**
     * Magic setter
	 * @param string $name
	 * @param mixed $value
	 */   	
	public function __set($name, $value)
	{
		if (in_array($name, $this->readOnly)) {
			throw new ReadOnlyPropertyException(get_class($this), $name);
		} elseif (in_array($name, $this->writeOnly)) {
			$this->$name = $value;	
		} else {
			throw new InaccessiblePropertyException(get_class($this), $name);
		}
	}
	
	/**
     * Contains the names of properties that should be read only
	 * @var array
	 */  	
	protected $readOnly  = array();
	
	/**
     * Contains the names of properties that should be write only
	 * @var array
	 */  	
	protected $writeOnly = array();
}

?>